package formin.powerbar.data;

public class Plug {
	private int plugNumber;
	private boolean[] onOffStatus;
	private String plugType;
	
	public Plug(int plugNumb){
		plugNumber = plugNumb;
		plugType = "";
		onOffStatus = new boolean[96];
		for (int i = 0; i < onOffStatus.length; i++) {
			onOffStatus[i]=true;
		}
	}
	
	
	public String getPlugString(){
		String temp = new String();
		for (int i = 0; i < 96; i++) {
			if (onOffStatus[i]==true){
				temp = temp + "8";
			}else{
				temp = temp + "_";
			}
		}
		return temp;
	}
	
	public void editOnOffCycle(int start, int end, boolean status){
		for(int i = start; i <= end; i++){
			onOffStatus[i] = status;
		}
	}
	
	public boolean getStatusAt(int numb){
		if((numb >= 0) & (numb < 96)){
			return onOffStatus[numb];
		}
		return false;
	}
	public void setStatusFromString(String str){
		String onOffString = str;
		if(onOffString == null){
			return;
		}
		for (int i = 0; i < onOffString.length(); i++) {
			if(onOffString.charAt(i)=='8'){
				onOffStatus[i] = true;
			}else {
				onOffStatus[i] = false;
			}
			
		}
	}
	public void setPlugType(String type){
		this.plugType = type;
	}
	public String getPlugType(){
		if(plugType != ""){
			return plugType;
		}
		return Constants.PLUG_DATAMODEL_TYPE_TIMER;
	}
	
	public void setStatusAt(int numb, boolean status){
		if((numb >= 0) & (numb < 96)){
			onOffStatus[numb] = status;
		}
	}
	public int getPlugNumber(){
		return plugNumber;
	}
}
